package org.geektimes.projects.user.validator.bean.validation.validator;

import org.geektimes.projects.user.domain.User;
import org.geektimes.projects.user.validator.bean.validation.annotation.IdRange;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.Objects;

public class IdRangeValidator implements ConstraintValidator<IdRange, User> {


   public void initialize(IdRange constraint) {
   }

   public boolean isValid(User user, ConstraintValidatorContext context) {

      if (Objects.isNull(user.getId()))
         return true;

      return user.getId() > 0;
   }
}
